﻿using System;
using System.Collections.Generic;
using AutoMapper;
using CodeSaude.Application.Interfaces;
using CodeSaude.Application.ViewModels;
using CodeSaude.Domain.Entities;
using CodeSaude.Domain.Interfaces.Service;

namespace CodeSaude.Application.Services
{
    public class LocalAtendimentoApplicationService : BaseApplicationService,  ILocalAtendimentoApplicationService
    {
        private readonly ILocalAtendimentoService _alergiaService;

        public LocalAtendimentoApplicationService(ILocalAtendimentoService alergiaService)
        {
            _alergiaService = alergiaService;
        }

        //public ValidationApplicationResult Add(GrupoUsuarioViewModel GrupoUsuarioViewModel)
        //{
        //    var usuario = Mapper.Map<GrupoUsuarioViewModel, Usuario>(GrupoUsuarioViewModel);

        //    var result = _usuarioService.AdicionarUsuario(usuario);

        //    //if(result.IsValid)
        //        _usuarioService.SaveChanges();

        //    return Mapper.Map<ValidationResult, ValidationApplicationResult>(result);
        //}

        public void Add(LocalAtendimentoViewModel alergiaViewModel)
        {
            var alergia = Mapper.Map<LocalAtendimentoViewModel, LocalAtendimento>(alergiaViewModel);

            BeginTransaction();
            _alergiaService.AdicionarLocalAtendimento(alergia);
            Commit();
        }

        public LocalAtendimentoViewModel GetById(int id)
        {
            return Mapper.Map<LocalAtendimentoViewModel>(_alergiaService.GetById(id));
        }

        public IEnumerable<LocalAtendimentoViewModel> GetAll()
        {
            return Mapper.Map<IEnumerable<LocalAtendimentoViewModel>>(_alergiaService.GetAll());
        }

        public void Update(LocalAtendimentoViewModel alergiaViewModel)
        {
            var alergia = Mapper.Map<LocalAtendimento>(alergiaViewModel);

            BeginTransaction();
            _alergiaService.Update(alergia);
            Commit();
        }

        public void Remove(LocalAtendimentoViewModel alergiaViewModel)
        {
            var user = _alergiaService.GetById(alergiaViewModel.LocalAtendimentoId);
            BeginTransaction();
            _alergiaService.Remove(user);
            Commit();
        }

        public void Dispose()
        {
            _alergiaService.Dispose();
        }
    }
}
